package cn.good.yan.controller;

import cn.good.yan.pojo.CommonResult;
import cn.good.yan.service.AccountService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;

/**
 * 账户服务
 *
 * @author shengren.yan
 * @create 2024-02-22
 */
@RestController
@Slf4j
public class AccountController {

    @Autowired
    private AccountService accountService;

    // 扣除 该账户的 金额
    @PostMapping("/account/decrease")
    @ResponseBody
    public CommonResult decrease(@RequestParam("userId") Long userId, @RequestParam("money") BigDecimal money) throws InterruptedException {
        // 模拟异常
//        Thread.sleep(20000);
        if (money.longValue() > 100l) {
            int s = 10 / 0;
        }
        accountService.decrease(userId, money);
        return new CommonResult(200, "扣减账户余额成功！");
    }


}
